package a66weding.com.jiehuntong.pager;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.map.Overlay;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.activity.ToolsWedRegisterActivity;
import a66weding.com.jiehuntong.beans.WedRegistryMapBean;

/**
 * @version :
 * @creator : AxDu
 * @create-time : 2016/6/7
 * @description :
 */
public class ToolsPager_WedRegistry extends BasePager {

    private ToolsWedRegisterActivity mWedRegisActivity;
    private MapView mMapView;
    private View pop;
    private TextView title;
    private WedRegistryMapBean wedRegistryMapBean;


    public ToolsPager_WedRegistry(Activity activity) {
        super(activity);
    }

    @Override
    protected View getView() {
        View mContentView = View.inflate(mActivity, R.layout.pager_tools_wedregister_mapinfo, null);
        mMapView = (MapView) mContentView.findViewById(R.id.bmapview_screeen);


        return mContentView;
    }

    @Override
    public void initData() {



        BitmapFactory bitmapFactory = new BitmapFactory();


        View popview = View.inflate(mActivity, R.layout.map_pop, null);
        Bitmap bitmap= getViewBitmap(popview);

        BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromBitmap(bitmap);

        //构建MarkerOption，用于在地图上添加Marker
        OverlayOptions option = new MarkerOptions().position(wedRegistryMapBean.getLocation()).icon(bitmapDescriptor);

        mMapView.getMap().addOverlay(option);

    }


    private void initPop() {
        pop = View.inflate(mActivity, R.layout.map_pop, null);
        title = (TextView) pop.findViewById(R.id.name);


        MapView.LayoutParams params = new MapView.LayoutParams(MapView.LayoutParams.WRAP_CONTENT,
                MapView.LayoutParams.WRAP_CONTENT);

        mMapView.addView(pop, params);



    }

    private Bitmap getViewBitmap(View addViewContent) {

        addViewContent.setDrawingCacheEnabled(true);

        addViewContent.measure(
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
        addViewContent.layout(0, 0,
                addViewContent.getMeasuredWidth(),
                addViewContent.getMeasuredHeight());

        addViewContent.buildDrawingCache();
        Bitmap cacheBitmap = addViewContent.getDrawingCache();
        Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);

        return bitmap;
    }

}
